package com.data.structure.demo01;

import java.util.LinkedList;
import java.util.Queue;

public class QueueDemo {
    public static void main(String[] args) {
        Queue<String> queue = new LinkedList<>();
        queue.add("str1");
        queue.add("str2");
        queue.add("str3");
        queue.add("str4");
        queue.add("str5");
        queue.add("str6");
        queue.add("str7");
        queue.add("str8");
        queue.add("str9");
        queue.add("str10");
        queue.iterator().forEachRemaining(System.out::println);
        String poll = queue.poll();//返回并移除头元素，队列是先进先进先出的，即：str1
        System.out.println("Poll value: "+poll); //移除的元素是poll
        String peek = queue.peek(); //返回头元素，队列是先进先出的,即：str2
        System.out.println("Peek value: "+peek);
        boolean str11 = queue.offer("str11"); //向队列的尾部添加元素，str11
        System.out.println("offer value: "+str11);
        queue.iterator().forEachRemaining(System.out::println);
        String poll1 = queue.poll();
        System.out.println("poll1 value : "+poll1);
        String peek1 = queue.peek();
        System.out.println("peek1 value: "+peek1);
        queue.iterator().forEachRemaining(System.out::println);
    }
}
